import React from "react";
import {Layout} from 'antd';

import BaseComponent from "../../../../../redare/components/BaseComponent";
import NavMenu from "./components/NavMenu";
import Header from "./components/Header";
import './index.scss';
import Switch from "../../../../../redare/components/router/Switch";

export default class IndexPage extends BaseComponent {

    static defaultProps = {
        siderWidth: 250,
        contentClassName: '',
        contentStyle: {},
        headerComponent: undefined,
        onLoginOut: undefined
    };

    constructor(props) {
        super(props);
    }

    _onLoginOut() {
        if (this.props.onLoginOut) {
            this.props.onLoginOut();
        }
    }

    render() {
        return (
            <Layout className="webplatform-workbench-index-common-container">
                <Layout>
                    <Layout.Sider collapsible>
                        <div className="ant-pro-sider-logo" id="logo">
                            <a><img src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg" alt="logo"/>
                                <h1>Generator</h1>
                            </a>
                        </div>
                        <NavMenu history={this.props.history}
                                 onRoutesReady={(routes) => this.setState({routes})}/>
                    </Layout.Sider>
                    <Layout>
                        <Layout.Header>
                            {this.props.headerComponent ? this.props.headerComponent :
                                <Header onLoginOut={this._onLoginOut.bind(this)}/>}
                        </Layout.Header>
                        <Layout.Content className={`content-container position-relative ${this.props.contentClassName}`}
                                        style={this.props.contentStyle}>
                            <Switch renderAllChildren={true}>
                                {
                                    this.state.routes
                                }
                            </Switch>
                        </Layout.Content>
                    </Layout>
                </Layout>
            </Layout>
    )
    }
    }
